From 5521f69cc9df0ab1e1bfb6c94ec64a473bb82fe2 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Wed, 16 Aug 2006 00:00:54 +0000 Subject: [PATCH] Force usage of common gbfile api. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@2303 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/arcdist.c | 8 ++++---- gpsbabel/pcx.c | 32 ++++++++++++++------------------ gpsbabel/polygon.c | 8 ++++---- gpsbabel/tiger.c | 45 ++++++++++++++++++++------------------------- 4 files changed, 42 insertions(+), 51 deletions(-) diff --git a/gpsbabel/arcdist.c b/gpsbabel/arcdist.c index c173c7ca5..ecbc75db2 100644 --- a/gpsbabel/arcdist.c +++ b/gpsbabel/arcdist.c @@ -60,12 +60,12 @@ arcdist_process(void) double lat1, lon1, lat2, lon2; int fileline = 0; char *line; - textfile_t *tin; + gbfile *file_in; - tin = textfile_open_read(arcfileopt, MYNAME ); + file_in = gbfopen(arcfileopt, "r", MYNAME); lat1 = lon1 = lat2 = lon2 = BADVAL; - while ((line = textfile_read(tin))) { + while ((line = gbfgetstr(file_in))) { char *pound = NULL; int argsfound = 0; @@ -123,7 +123,7 @@ arcdist_process(void) lon1 = lon2; } - textfile_done(tin); + gbfclose(file_in); QUEUE_FOR_EACH(&waypt_head, elem, tmp) { waypoint *wp = (waypoint *) elem; diff --git a/gpsbabel/pcx.c b/gpsbabel/pcx.c index 2d6b5764d..b6c33d66d 100644 --- a/gpsbabel/pcx.c +++ b/gpsbabel/pcx.c @@ -24,8 +24,7 @@ #include "garmin_tables.h" #include -static FILE *file_in; -static FILE *file_out; +static gbfile *file_in, *file_out; static short_handle mkshort_handle; static short_handle mkshort_handle2; /* for track and route names */ static char *deficon = NULL; @@ -48,19 +47,19 @@ arglist_t pcx_args[] = { static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = gbfopen(fname, "rb", MYNAME); } static void rd_deinit(void) { - fclose(file_in); + gbfclose(file_in); } static void wr_init(const char *fname) { - file_out = xfopen(fname, "w", MYNAME); + file_out = gbfopen(fname, "w", MYNAME); mkshort_handle = mkshort_new_handle(); mkshort_handle2 = mkshort_new_handle(); } @@ -68,7 +67,7 @@ wr_init(const char *fname) static void wr_deinit(void) { - fclose(file_out); + gbfclose(file_out); mkshort_del_handle(&mkshort_handle); mkshort_del_handle(&mkshort_handle2); } @@ -91,12 +90,10 @@ data_read(void) route_head *route = NULL; int n; char lathemi, lonhemi; - textfile_t *tin; read_as_degrees = 0; - tin = textfile_init(file_in); - while ((buff = textfile_read(tin))) + while ((buff = gbfgetstr(file_in))) { char *ibuf = lrtrim(buff); char *cp; @@ -217,7 +214,6 @@ data_read(void) ; } } - textfile_done(tin); } static void @@ -246,7 +242,7 @@ gpsutil_disp(const waypoint *wpt) } - fprintf(file_out, "W %-6.6s %c%08.5f %c%011.5f %s %5d %-40.40s %5e %d\n", + gbfprintf(file_out, "W %-6.6s %c%08.5f %c%011.5f %s %5d %-40.40s %5e %d\n", global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, @@ -275,10 +271,10 @@ pcx_track_hdr(const route_head *trk) * so provide option to supppress these. */ if (!cartoexploreur) { - fprintf(file_out, "\n\nH TN %s\n", name); + gbfprintf(file_out, "\n\nH TN %s\n", name); } xfree(name); - fprintf(file_out, "H LATITUDE LONGITUDE DATE TIME ALT ;track\n"); + gbfprintf(file_out, "H LATITUDE LONGITUDE DATE TIME ALT ;track\n"); } static void @@ -294,9 +290,9 @@ pcx_route_hdr(const route_head *rte) /* see pcx_track_hdr */ if (!cartoexploreur) { - fprintf(file_out, "\n\nR %s\n", name); + gbfprintf(file_out, "\n\nR %s\n", name); } - fprintf(file_out, "\n" + gbfprintf(file_out, "\n" "H IDNT LATITUDE LONGITUDE DATE TIME ALT DESCRIPTION PROXIMITY SYMBOL ;waypts\n"); } @@ -317,7 +313,7 @@ pcx_track_disp(const waypoint *wpt) for (tp = tbuf; *tp; tp++) { *tp = toupper(*tp); } - fprintf(file_out, "T %c%08.5f %c%011.5f %s %.f\n", + gbfprintf(file_out, "T %c%08.5f %c%011.5f %s %.f\n", lat < 0.0 ? 'S' : 'N', fabs(lat), lon < 0.0 ? 'W' : 'E', @@ -329,7 +325,7 @@ pcx_track_disp(const waypoint *wpt) static void data_write(void) { -fprintf(file_out, +gbfprintf(file_out, "H SOFTWARE NAME & VERSION\n" "I PCX5 2.09\n" "\n" @@ -347,7 +343,7 @@ fprintf(file_out, if (global_opts.objective == wptdata) { - fprintf(file_out, + gbfprintf(file_out, "\n" "H IDNT LATITUDE LONGITUDE DATE TIME ALT DESCRIPTION PROXIMITY SYMBOL ;waypts\n"); diff --git a/gpsbabel/polygon.c b/gpsbabel/polygon.c index 6fc79fcd3..5f2abce18 100644 --- a/gpsbabel/polygon.c +++ b/gpsbabel/polygon.c @@ -256,12 +256,12 @@ polygon_process(void) int first = 1; int last = 0; char *line; - textfile_t *tin; + gbfile *file_in; - tin = textfile_open_read(polyfileopt, MYNAME ); + file_in = gbfopen(polyfileopt, "r", MYNAME); olat = olon = lat1 = lon1 = lat2 = lon2 = BADVAL; - while ((line = textfile_read(tin))) { + while ((line = gbfgetstr(file_in))) { char *pound = NULL; int argsfound = 0; @@ -327,7 +327,7 @@ polygon_process(void) lon1 = lon2; } } - textfile_done(tin); + gbfclose(file_in); QUEUE_FOR_EACH(&waypt_head, elem, tmp) { waypoint *wp = (waypoint *) elem; diff --git a/gpsbabel/tiger.c b/gpsbabel/tiger.c index d97511e6d..364e548a0 100644 --- a/gpsbabel/tiger.c +++ b/gpsbabel/tiger.c @@ -22,8 +22,7 @@ #include "defs.h" #include "csv_util.h" -static FILE *file_in; -static FILE *file_out; +static gbfile *file_in, *file_out; static short_handle mkshort_handle; static short_handle mkshort_whandle; @@ -99,28 +98,28 @@ arglist_t tiger_args[] = { static void rd_init(const char *fname) { - file_in = xfopen(fname, "rb", MYNAME); + file_in = gbfopen(fname, "rb", MYNAME); mkshort_handle = mkshort_new_handle(); } static void rd_deinit(void) { - fclose(file_in); + gbfclose(file_in); mkshort_del_handle(&mkshort_handle); } static void wr_init(const char *fname) { - file_out = xfopen(fname, "w", MYNAME); + file_out = gbfopen(fname, "w", MYNAME); thresh_days = strtod(oldthresh, NULL); } static void wr_deinit(void) { - fclose(file_out); + gbfclose(file_out); } static void @@ -131,11 +130,8 @@ data_read(void) char icon[100]; char *ibuf; waypoint *wpt_tmp; - textfile_t *tin; - - tin = textfile_init(file_in); - while ((ibuf = textfile_read(tin))) { + while ((ibuf = gbfgetstr(file_in))) { if( sscanf(ibuf, "%lf,%lf:%100[^:]:%100[^\n]", &lon, &lat, icon, desc)) { wpt_tmp = waypt_new(); @@ -148,7 +144,6 @@ data_read(void) waypt_add(wpt_tmp); } } - textfile_done(tin); } static void @@ -174,7 +169,7 @@ tiger_disp(const waypoint *wpt) if (lon < minlon) minlon = lon; } - fprintf(file_out, "%f,%f:%s", lon, lat, pin); + gbfprintf(file_out, "%f,%f:%s", lon, lat, pin); if (!nolabels) { char *temp = NULL; char *desc = csv_stringclean(wpt->description, ":"); @@ -183,11 +178,11 @@ tiger_disp(const waypoint *wpt) temp = desc; desc = mkshort(mkshort_whandle, desc); } - fprintf(file_out, ":%s", desc); + gbfprintf(file_out, ":%s", desc); if (temp != NULL) desc = temp; xfree(desc); } - fprintf(file_out, "\n"); + gbfprintf(file_out, "\n"); } #if CLICKMAP @@ -200,7 +195,7 @@ map_plot(const waypoint *wpt) x+=10; y+=10; - fprintf(linkf, "\"%s\"\n",url, wpt->description); + gbfprintf(linkf, "\"%s\"\n",url, wpt->description); } #endif /* CLICKMAP */ @@ -240,13 +235,13 @@ data_write(void) setshort_length(mkshort_whandle, short_length); - fprintf(file_out, "#tms-marker\n"); + gbfprintf(file_out, "#tms-marker\n"); waypt_disp_all(tiger_disp); if (genurl) { - FILE *urlf; + gbfile *urlf; - urlf = xfopen(genurl, "w", MYNAME); + urlf = gbfopen(genurl, "w", MYNAME); latsz = fabs(maxlat - minlat); lonsz = fabs(maxlon - minlon); @@ -254,21 +249,21 @@ data_write(void) * Center the map along X and Y axis the midpoint of * our min and max coords each way. */ - fprintf(urlf, "lat=%f&lon=%f&ht=%f&wid=%f", + gbfprintf(urlf, "lat=%f&lon=%f&ht=%f&wid=%f", minlat + (latsz/2.0), minlon + (lonsz/2.0), dscale(latsz), dscale(lonsz)); - fprintf(urlf, "&iwd=%s&iht=%s", xpixels, ypixels); - fclose(urlf); + gbfprintf(urlf, "&iwd=%s&iht=%s", xpixels, ypixels); + gbfclose(urlf); #if CLICKMAP if (clickmap) { - linkf = xfopen(clickmap, "w", MY NAME); - fprintf(linkf, "\n"); + linkf = gbfopen(clickmap, "w", MY NAME); + gbfprintf(linkf, "\n"); waypt_disp_all(map_plot); - fprintf(linkf, "\n"); - fclose(linkf); + gbfprintf(linkf, "\n"); + gbfclose(linkf); linkf = NULL; } #endif -- 2.30.2